const express = require('express');
const config = require('config');
const app = express();
const Multer = require('multer');
const path = require('path');

const auth = require("./routes/auth.js");
const common = require("./routes/common.js");
const upload = require("./routes/upload.js");
const search = require("./routes/search.js");
const detail = require("./routes/detail.js");
const comment = require("./routes/comment.js");
const project = require("./routes/project.js");
const my = require("./routes/my.js");
const admin = require("./routes/admin.js");
const file_download = require("./routes/file_download.js");

var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());


// 认证模块
app.use('/api/auth',auth);
// 公共接口
app.use('/api/common',common);
// 上传模块
app.use('/api/upload',upload);
// 搜索模块
app.use('/api/search',search);
// 查看详情模块
app.use('/api/detail',detail);
// 评分评论模块
app.use('/api/comment',comment);
// 项目模块
app.use('/api/project',project);
// 个人中心模块
app.use('/api/my',my);
// 管理后台模块
app.use('/api/admin',admin);
// 下载模块
app.use('/api/file_download',file_download);


// 设置uploads为静态目录
app.use('/download', express.static(path.join(__dirname, 'uploads')));

app.get('/download', function(req, res){
    var file = __dirname + '/uploads/'+req.query.filename;
    res.download(file); 
 });

app.use(express.static(__dirname + '/temp'));

// PORT
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`正在监听${port}端口`));